package com.tcm.doctor.web.controller;

import com.base.core.exception.ServiceException;
import com.base.core.utils.R;
import com.tcm.doctor.domain.dto.DoctorServicesDTO;
import com.tcm.doctor.service.DoctorServicesService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/doctor")
@RestController
public class DoctorServicesController {

    @DubboReference(version = "0.0.1-alpha", timeout = 6000, check = false, retries = 3)
    private DoctorServicesService doctorServicesService;

    @GetMapping("/services/list")
    public R listServices(@RequestParam("doctorId") Long doctorId) {
       return R.success(doctorServicesService.listServices(doctorId));
    }

    @PostMapping("/services/save")
    public R save(@RequestBody DoctorServicesDTO doctorServicesDTO) {
        try{
            doctorServicesService.save(doctorServicesDTO);
        }catch (ServiceException e){
            return R.fail(e.getResult().getCode(), e.getMessage());
        }catch (Exception e){
            return R.fail(e.getMessage());
        }
        return R.success();
    }

}

